package redis;

import org.junit.Test;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class Demo1 {

	@Test
	public void Demo1(){
		//设置IP地址和端口
		Jedis jedis = new Jedis("192.168.136.128",6379);
		jedis.set("name2", "luorong");
		String value = jedis.get("name");
		//释放资源
		jedis.close();
	}
	
	@Test
	public void Demo2(){
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(300);
		JedisPool jedisPool = new JedisPool(config,"192.168.136.128",6379);
		Jedis jedis = null;
		try{
			jedis = jedisPool.getResource();
			jedis.set("name2", "luorong2");
			String value = jedis.get("name2");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			if(jedis != null){
				jedis.close();
			}
			if(jedisPool != null){
				jedisPool.close();
			}
		}
	}
}
